package com.course.server.service;

import com.course.server.dto.CourseContentFileDto;
import com.course.server.entity.CourseContentFile;
import com.course.server.entity.CourseContentFileExample;
import com.course.server.mapper.CourseContentFileMapper;
import com.course.server.util.CopyUtil;
import com.course.server.util.UuidUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: Durian
 * @date: 2021/5/9 19:13
 */
@Service
public class CourseContentFileService {

    @Resource
    private CourseContentFileMapper courseContentFileMapper;

    public void delete(String id) {
        courseContentFileMapper.deleteByPrimaryKey(id);
    }

    public void save(CourseContentFileDto courseContentFileDto) {
        courseContentFileDto.setId(UuidUtils.getShortUuid());
        courseContentFileMapper.insert(CopyUtil.copy(courseContentFileDto, CourseContentFile.class));
    }

    public List<CourseContentFileDto> list(String courseId) {
        CourseContentFileExample example = new CourseContentFileExample();
        // criteria只能一次
        example.createCriteria().andCourseIdEqualTo(courseId);
        List<CourseContentFile> courseContentFiles = courseContentFileMapper.selectByExample(example);
        return CopyUtil.copyList(courseContentFiles, CourseContentFileDto.class);
    }
}
